import java.util.*;

class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] array = str.toCharArray();

            Arrays.sort(array);
            String s = new String(array);
            List<String> list = map.getOrDefault(s,new ArrayList<String>());
            list.add(str);

            map.put(s,list);

        }

        return new ArrayList<>(map.values());
    }
}